package com.wdc.sort;

import com.wdc.queue.Arr;

import java.util.ArrayList;
import java.util.Arrays;

public class RadixSort {

    public static void radixSort(String[] a , int length){
        //1.准备桶
        ArrayList<String>[] buckets = new ArrayList[10];
        for (int i = 0; i < buckets.length; i++) {
            buckets[i] = new ArrayList<>();
        }

        for (int i = length -1; i >= 0; i--) {
            for (String s : a) {
                buckets[ s.charAt(i) - '0'].add(s);
            }
            int k = 0;
            for (ArrayList<String> bucket : buckets) {
//            System.out.println(bucket);
                for (String s : bucket) {
                    a[k++] = s;
                }
                bucket.clear();
            }


        }
        System.out.println(Arrays.toString(a));





    }

    public static void main(String[] args) {
        String[] phoneNumber = new String[6];
        phoneNumber[0] = "12134578942";
        phoneNumber[1] = "13423498756";
        phoneNumber[2] = "17094837264";
        phoneNumber[3] = "15712345678";
        phoneNumber[4] = "16712345678";
        phoneNumber[5] = "14512345678";

        radixSort(phoneNumber,11);


    }




}
